/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.capex.farmacus.Manager;

import edu.capex.farmacus.controllers.MedicamentosJpaController;
import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author IK
 */
public class MedicamentosManager extends MedicamentosJpaController implements Serializable {

    public MedicamentosManager(EntityManagerFactory emf) {
        super(emf);
    }

    public MedicamentosManager() {
        super(Persistence.createEntityManagerFactory("farmacusPU"));
    }

    public Integer nextId() {
        EntityManager em = getEntityManager();
        Integer ultimoId = 0;
        try {
            Query query = em.createQuery("SELECT a.idmedicamentos FROM Medicamentos a ORDER BY a.idmedicamentos desc");
            query.setMaxResults(1);
            ultimoId = (Integer) query.getSingleResult();
        } catch (NoResultException ex) {
            ultimoId = 0;
        }finally {
            em.close();
        }

        return ultimoId + 1;
    }

    public static void main(String[] args) {
        new MedicamentosManager();
    }
}
